<template>
  <div class="table-like-arr__th"> <el-checkbox class="table-like-arr__ck"
      v-model="checked" @change="handleCheckedCitiesChange(scope, $event)"></el-checkbox> {{scope.indexKey + 1}}</div>
</template>

<script>
export default {
  name: "FormCheckedTr",
  props: [
    'scope'
  ],
  inject: ['form_aaa', 'zformLoader'],
  data() {
    return {
      checkAll: false,
      checked: false,
      // cities: [],
      isIndeterminate: true
    }
  },
  mounted() {
    // console.log(this.form_aaa)
    this.form_aaa.mitt.on('all-change', this.handle)
    this.form_aaa.mitt.on('clear-all', this.handleC)
  },
  beforeDestroy() {
    this.form_aaa.mitt.off('all-change', this.handle)
    this.form_aaa.mitt.off('clear-all', this.handleC)
  },
  methods: {
    handleC() {
      this.checked = false
    },
    handle({model} = {}) {
      this.checked = !!this.form_aaa.getCheck()[this.scope.indexKey]
    },
    handleCheckedCitiesChange(scope, value) {
      // let model =  this.zformLoader.getCurIns().getModel()
      // let arr = ZY.lodash.get(model, scope.pathArr);

      this.form_aaa.setCheckByIndex(scope.indexKey, value, scope)
      // let checkedCount = this.form_aaa.getCheck().filter(v => v).length;
      // this.checkAll = checkedCount === arr.length;
      // if (arr.length < 1) {
      //   this.checkAll = false
      // }
      // this.isIndeterminate = checkedCount > 0 && checkedCount < arr.length;
      this.$nextTick(() => {
        this.form_aaa.mitt.emit('tr-change', {
          // model: {
          //   checkAll: this.checkAll,
          //   isIndeterminate: this.isIndeterminate
          // }
        })
        this.form_aaa.reload()
      })
    }
  }
}
</script>

<style scoped>

</style>
